package graph.group.zhangtao.guider.utils;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.List;

import graph.group.zhangtao.guider.model.ViewKey;

/**
 * Created by tao on 18-3-19.
 */

public class GetLocalFiles {
    public static String getLocalPath() {
        return LOCAL_PATH;
    }

    public static void setLocalPath(String localPath) {
        LOCAL_PATH = localPath;
    }

    private static String LOCAL_PATH = "";

    private static final String LOCAL_DIR = "DownloadViews";

    public static String getFullDirPath() {
        return LOCAL_PATH + LOCAL_DIR + "/";
    }

    public static final List<ViewKey> viewKeys = new LinkedList<>();

    public static List<ViewKey> initLocalViewKeys() {
        File root =new File(getFullDirPath());
        if(!root.exists()||!root.isDirectory()){
            root.mkdirs();
        }
        File file = new File(getFullDirPath());
        Log.w("tao", file.getAbsolutePath());
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (File f : files) {
                if (f.isDirectory()) {
                    ViewKey viewKey = new ViewKey(f.getName());
                    viewKey.setLocal(true);
                    viewKeys.add(viewKey);
                }
            }
        }


        return viewKeys;
    }

    public static InputStream GetFromFile(String path) {
        BufferedInputStream bufferedInputStream = null;
        try {
            bufferedInputStream = new BufferedInputStream(
                    new FileInputStream(path));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return bufferedInputStream;
    }
}
